//
//  chooseGrade.m
//  ZHIDOU
//
//  Created by 向礼 on 2018/12/24.
//  Copyright © 2018 向礼. All rights reserved.
//

#import "chooseGrade.h"

static chooseGrade *_instance = nil;
@interface chooseGrade()
@property(nonatomic ,strong)UIView *BgView;
@property(nonatomic ,assign)BOOL showOrHed;
@end

@implementation chooseGrade

-(instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self loadBodyView];
    }
    return self;
}

-(void)loadBodyView{
    self.backgroundColor = ZD_UIColorRGB_alpha(0, 0, 0,0.5);
    _BgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 305)];
    _BgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_BgView];
    NSArray *xiaoueArr = @[@"一年级",@"二年级",@"三年级",@"四年级",@"五年级",@"六年级"];
    NSArray *chuzhongArr = @[@"初一",@"初二",@"初三"];
    NSArray *gaozhongArr = @[@"高一",@"高二",@"高三"];
    [self School:@"小学" andGradeNSArray:xiaoueArr andY:0];
    [self School:@"初中" andGradeNSArray:chuzhongArr andY:125];
    [self School:@"高中" andGradeNSArray:gaozhongArr andY:207];
}

- (void)School:(NSString *)school andGradeNSArray:(NSArray *)gradeArr andY:(CGFloat)weizhiY{
   // self.backgroundColor = [UIColor whiteColor];
    UILabel *xiaoxue = [[UILabel alloc] init];
    xiaoxue.frame = CGRectMake(20,weizhiY+23,50,14);
    xiaoxue.numberOfLines = 0;
    xiaoxue.font = [UIFont systemFontOfSize:12];
    xiaoxue.text = school;
    xiaoxue.textColor = UIColorFromRGB(0x999999);
    [_BgView addSubview:xiaoxue];
    CGFloat  gradeWith = (self.width- 76)/3;
    
    for (int i =0; i<gradeArr.count; i++) {
        int yu = i%3;///余
        int bei = i/3;//倍数
        UIButton *grade = [UIButton buttonWithType:UIButtonTypeCustom];
        grade.frame = CGRectMake(20 + (gradeWith+18)*yu,weizhiY+50+44*bei ,gradeWith,29);
        grade.backgroundColor = UIColorFromRGB(0xF2F2F2);
       // grade.textAlignment = NSTextAlignmentCenter;
       //grade.font=[UIFont systemFontOfSize:12];
        grade.titleLabel.font = [UIFont systemFontOfSize:12];
        grade.layer.cornerRadius = 14.5;
        grade.layer.masksToBounds = YES;
        [grade setTitle:gradeArr[i] forState:UIControlStateNormal];
        [grade setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
      //  grade.text = gradeArr[i];
        [_BgView addSubview:grade];
    }
}

+ (void)showAlter: (UIViewController *)Controller{
    if (!_instance) {
        _instance = [[chooseGrade alloc] initWithFrame:(CGRect){0, 0, ZD_screenWidth, ZD_screenHeight}];
        [Controller.view addSubview:_instance];
        [UIView animateWithDuration:0.25 animations:^{
            _instance.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
        }];
    }else{
        [UIView animateWithDuration:0.15 animations:^{
            _instance.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0];
        } completion:^(BOOL finished) {
            [_instance removeFromSuperview];
            _instance = nil;
        }];
    }
   
}



@end
